﻿<?php 
session_start();
include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$DBsql = new DB_Oracle ();
//查询所以警员
if(isset($_GET['option'])){
if($_GET['option']=="all"){
	$sql="insert into tts_ctrl(ctrl_id,ctrl_opreator,ctrl_content,send_flag,ctrl_times,device_id) select CTRL_ID_INDEX.NEXTVAL,'".$_SESSION['name']."','".$_GET['is']."','0',sysdate,t.device_id from  dep_vehicle t";
	$DBsql->query($sql);
	exit();
	}
	else{
	$arr=explode(",",$_GET['str']);
for($i=0;$i<count($arr);++$i){
$sql="insert into tts_ctrl(ctrl_id,ctrl_opreator,ctrl_content,send_flag,ctrl_times,device_id) values(CTRL_ID_INDEX.NEXTVAL,'".$_SESSION['name']."','".$_GET['is']."','0',sysdate,".$arr[$i].")";
	$DBsql->query($sql);
	}
	}
	exit();
	}
//查询所有的派出所
$sql="select dd.department_index, dd.department_name
		  from dep_department dd
		 order by dd.department_index";
$dedp=$DBsql->fetch_all_array($sql);



$sql="select * from dep_vehicle";
$rows=$DBsql->fetch_all_array($sql);
if(empty($_GET['departmentID'])){
$pageSize = 15;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
	  from (select rownum r,b.device_id,b.license_plate,TO_CHAR(b1.ctrl_times, 'YYYY-MM-DD HH24:MI:SS') stime,TO_CHAR(b1.ctrl_timee, 'YYYY-MM-DD HH24:MI:SS') etime,b1.ctrl_content,b1.ctrl_opreator from dep_vehicle b left join (select t1.* from tts_ctrl t1,(select t.device_id,max(t.ctrl_timee) stime from tts_ctrl t where t.send_flag='1' group by t.device_id) t2 
where t1.device_id=t2.device_id and t1.ctrl_timee=t2.stime) b1 on b.device_id=b1.device_id) c
	 where c.r > $firstcount
	   and c.r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);
}
else
{
	$depID=$_GET['departmentID'];
			$sql="select dp.vehicle_index from dep_vehicle dp where dp.department_index=$depID";
	$rows=$DBsql->fetch_all_array($sql);
$pageSize = 15;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
	  from (select rownum r,b.device_id,b.license_plate,TO_CHAR(b1.ctrl_times, 'YYYY-MM-DD HH24:MI:SS') stime,TO_CHAR(b1.ctrl_timee, 'YYYY-MM-DD HH24:MI:SS') etime,b1.ctrl_content,b1.ctrl_opreator from (select * from dep_vehicle where department_index=$depID) b left join (select t1.* from tts_ctrl t1,(select t.device_id,max(t.ctrl_timee) stime from tts_ctrl t where t.send_flag='1' group by t.device_id) t2 
where t1.device_id=t2.device_id and t1.ctrl_timee=t2.stime) b1 on b.device_id=b1.device_id) c
	 where c.r > $firstcount
	   and c.r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);
	}
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script> 
<script language="javascript">
function department(str){
	var url="tts_ctrl.php?"+encodeURI("dep="+str);
	window.location=url;  
	}
function CheckAll(obj){var chebox=document.getElementsByName('checkbox_id');if(obj.checked==true){
for(var i=0;i<chebox.length;++i){chebox.item(i).checked=true;}}else{for(var i=0;i<chebox.length;++i){chebox.item(i).checked=false;}}
}


function UP(){
	var obj=document.getElementById('select').value;
	if(obj==2){
		alert("没有选中控制状态");
		return 0;
		}	
if(document.getElementsByName('radio').item(1).checked==true){
	$.ajax({
			type:"GET",
			url:"tts_ctrl.php",
			cache:false,
			data:encodeURI("option=all&is="+obj),
			success:function(data){
					alert('更新成功'); 
	               window.location="tts_ctrl.php";
			}
		});
	return 0;
	}
var chebox=document.getElementsByName('checkbox_id');
var n=0;
var str="";
for(var i=0;i<chebox.length;++i){
	if(chebox.item(i).checked==true){
		n++;
		str+=chebox.item(i).value+",";
		}}
		if(n==0){
			alert("没有选择要控制的设备");
			return 0;
			}
	str=str.substr(0,str.length-1);
			$.ajax({
			type:"GET",
			url:"tts_ctrl.php",
			cache:false,
			data:encodeURI("option=change&str="+str+"&is="+obj),
			success:function(data){
					alert('更新成功'); 
	window.location="tts_ctrl.php";
			}
		});
		}
document.ondblclick = function(){
	POPdiv('selectLocation');
};
function groupSelect(){
	var policeID=$("#selectID").val();
	$('#departmentID').val(policeID);
	$('#Location').submit();
}
</script>
 
<!--管理列表开始-->
<div class="manageTab" style="margin-top:0px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv">
      <span>
            <input name="radio" type="radio" checked="checked" />部分修改
  <input name="radio" type="radio"/>全部修改
          </span>
      <span>
          <input type="checkbox" id="checkall" name="" value="" onclick="CheckAll(this)" />
          全选</span>
          <span>
          <select id="select"><option value="2">选择状态</option><option value="1">开</option><option value="0">关</option></select></span><span><input type="button" onclick="UP()" value="更新" /></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">版本更改</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td  class="td90b2">选择</td>
            <td  class="td90b2">车牌号</td>
            <td  class="td90b2">提交控制时间</td>
             <td  class="td90b2">控制时间</td>
             <td  class="td90b2">状态</td>
             <td  class="td90b2">作者</td>
          </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
          	?>
	          <tr>
	            <td class="tdfff"><input type='checkbox' name="checkbox_id" class="STYLE2" value="<?php echo $ros['DEVICE_ID'];?>" /></td>
	            <td class="tdfff"><?php if($ros['LICENSE_PLATE']==""){echo "没有数据";}else echo $ros['LICENSE_PLATE'];?></td>
	            <td class="tdfff"><?php if($ros['STIME']==""){echo "没有数据";}else echo $ros['STIME'];?></td>
	            <td class="tdfff"><?php if($ros['ETIME']==""){echo "没有数据";}else echo $ros['ETIME'];?></td>
	            <td class="tdfff"><?php if($ros['CTRL_CONTENT']=='1')echo "开启";else if($ros['CTRL_CONTENT']=="")echo "没有数据"; else echo "关闭";?></td>
                <td class="tdfff"><?php if($ros['CTRL_OPREATOR']==""){echo "没有数据";}else echo $ros['CTRL_OPREATOR'];?></td>
	          </tr>
          <?php }}else{echo '暂无数据！';}?>
          <tr>
            <td colspan="10" class="tdfff">&nbsp;</td>
          </tr>
        </table></td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
      <td height="24" width="8"><img src="images/user_03.gif" height="24" width="8" /></td>
      <td style="background:#3980b2;"><div class="green-black"><?php echo $pagenav;?>
        </div></td>
      <td height="24" width="8"><img src="images/user_04.gif" height="24" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->
<!--弹出层选择派出所开始-->
<div id="selectLocation" class="POPdiv">
	 <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('selectLocation')"><img src="images/ico_close.jpg" alt="关闭" /></a>分组查看</div>
        <div class="POPdiv_content">
        	<form id="Location" action="tts_ctrl.php" method="get">
	        	 <table border="0" cellpadding="5" cellspacing="0">
				    <tr>
				      <td width="80"><label for="selectID">选择派出所</label></td>
				      <td>
					  	<select id="selectID" name="selectID" onchange="groupSelect()">
							<option value="">全部</option>
							 <?php 
					          	foreach ($dedp as $row){
					         ?>
					         	<option <?php if(isset($_GET['departmentID'])){if($_GET['departmentID']==$row['DEPARTMENT_INDEX']){echo 'selected=selected';}}?> value="<?php echo $row['DEPARTMENT_INDEX'];?>"><?php echo $row['DEPARTMENT_NAME'];?></option>	
					         <?php
					          	}
					         ?>
						</select>
					  </td>
				      <td><input type="hidden" id="departmentID" name="departmentID" value=""></td>
				    </tr>
				 </table>
			 </form>
		</div>
</div>
<!--弹出层选择派出所结束-->